home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ctutor.arc / CHAP1.TXT < prev    next >
Encoding:
Text File  |  1988-02-28  |  7.9 KB  |  191 lines

  1.                         Chapter 1 - Getting Started
  2.  
  3.  
  4.                           WHAT IS AN IDENTIFIER?
  5.  
  6.              Before you can do anything in any language, you must at 
  7.  
  8.         least  know  how you name an identifier.   An identifier  is 
  9.  
  10.         used for any variable,  function,  data definition, etc.  In 
  11.  
  12.         the programming language C,  an identifier is a  combination 
  13.  
  14.         of alphanumeric characters,  the first being a letter of the 
  15.  
  16.         alphabet or an underline, and the remaining being any letter 
  17.  
  18.         of the alphabet,  any numeric digit,  or the underline.  Two 
  19.  
  20.         rules must be kept in mind when naming identifiers.
  21.  
  22.         1.   The  case  of  alphabetic  characters  is  significant.  
  23.  
  24.              Using  "INDEX" for a variable is not the same as  using 
  25.  
  26.              "index"  and  neither  of them is  the  same  as  using 
  27.  
  28.              "InDeX"  for a variable.   All three refer to different 
  29.  
  30.              variables.
  31.  
  32.         2.   As C is defined, up to eight significant characters can 
  33.  
  34.              be  used and will be considered significant.   If  more      
  35.  
  36.              than  eight  are  used,  they may  be  ignored  by  the      
  37.  
  38.              compiler.   This  may  or  may  not  be  true  of  your 
  39.  
  40.              compiler.  You  should  check your reference manual  to 
  41.  
  42.              find  out how many characters are significant for  your 
  43.  
  44.              compiler.
  45.  
  46.              It  should be pointed out that some C  compilers  allow 
  47.  
  48.         use of a dollar sign in an identifier name,  but since it is 
  49.  
  50.         not  universal,  it  will  not  be  used  anywhere  in  this 
  51.  
  52.         tutorial.    Check  your  documentation  to  see  if  it  is 
  53.  
  54.         permissible for your particular compiler.
  55.  
  56.                          WHAT ABOUT THE UNDERLINE?
  57.  
  58.              Even  though  the  underline can be used as part  of  a 
  59.  
  60.         variable  name,   it  seems  to  be  used  very  little   by 
  61.  
  62.         experienced   C  programmers.    It  adds  greatly  to   the 
  63.  
  64.         readability  of  a  program  to use  descriptive  names  for 
  65.  
  66.         variables  and  it  would be to your  advantage  to  do  so.  
  67.  
  68.         Pascal  programmers tend to use long descriptive names,  but 
  69.  
  70.         most C programmers tend to use short cryptic names.  Most of 
  71.  
  72.         the  example programs in this tutorial use very short  names 
  73.  
  74.         for that reason.
  75.  
  76.              Any computer program has two entities to consider,  the 
  77.  
  78.         data,  and  the program.   They are highly dependent on  one 
  79.  
  80.         another  and  careful planning of both will lead to  a  well 
  81.  
  82.         planned and well written program.   Unfortunately, it is not 
  83.  
  84.         possible  to study either completely without a good  working 
  85.  
  86.         knowledge of the other.  For this reason, this tutorial will 
  87.  
  88.         jump  back  and forth between teaching  methods  of  program 
  89.  
  90.         writing  and  methods of data  definition.    Simply  follow 
  91.  
  92.  
  93.  
  94.                                  Page 4
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.                         Chapter 1 - Getting Started
  105.  
  106.  
  107.         along and you will have a good understanding of both.   Keep 
  108.  
  109.         in  mind that,  even though it seems expedient to  sometimes 
  110.  
  111.         jump right into the program coding,  time spent planning the 
  112.  
  113.         data  structures  will be well spent and the  final  program 
  114.  
  115.         will reflect the original planning.
  116.  
  117.                         HOW THIS TUTORIAL IS WRITTEN
  118.  
  119.              As  you go through the example programs,  you will find 
  120.  
  121.         that  every  program  is complete.   There  are  no  program 
  122.  
  123.         fragments that could be confusing.   This allows you to  see 
  124.  
  125.         every  requirement that is needed to use any of the features 
  126.  
  127.         of C as they are presented.  Some tutorials I have seen give 
  128.  
  129.         very few, and very complex examples.  They really serve more 
  130.  
  131.         to  confuse  the student.   This tutorial  is  the  complete 
  132.  
  133.         opposite  because  it  strives to cover each new  aspect  of 
  134.  
  135.         programming  in  as  simple a  context  as  possible.   This 
  136.  
  137.         method,  however,  leads  to a lack of knowledge in how  the 
  138.  
  139.         various  parts  are combined.   For that  reason,  the  last 
  140.  
  141.         chapter is devoted entirely to using the features taught  in 
  142.  
  143.         the  earlier  chapters.  It will illustrate how to  put  the 
  144.  
  145.         various features together to create a usable program.   They 
  146.  
  147.         are given for your study,  and are not completely explained.  
  148.  
  149.         Enough  details of their operation are given to allow you to 
  150.  
  151.         understand how they work after you have completed all of the 
  152.  
  153.         previous lessons. 
  154.  
  155.                      A DISCUSSION OF SOME OF THE FILES
  156.  
  157.                                    CCL.BAT
  158.  
  159.              This  file,  which  does not exist on the  distribution 
  160.  
  161.         disk,  is the batch file that calls in an editor,  then  the 
  162.  
  163.         compiler (Pass 1 and Pass 2, if it exists), and finally runs 
  164.  
  165.         the resulting compiled program.   There are several examples 
  166.  
  167.         of  batch  files  which can be used with  various  compilers 
  168.  
  169.         given  in  the  "COMPILER.DOC"  file  on  the   distribution 
  170.  
  171.         diskette.   It  is up to you to type in a batch file for use 
  172.  
  173.         with your particular compiler,  considering also the  method 
  174.  
  175.         required to call in your editor.  To use it, simply type the 
  176.  
  177.         batchfile  name with the desired filename.   After typing in 
  178.  
  179.         your particular CCL.BAT file,  try it by typing CCL FIRSTEX.  
  180.  
  181.         You  will  get the source file displayed on the  monitor  by 
  182.  
  183.         your editor.   If you don't have one of the compilers listed 
  184.  
  185.         in  the  "COMPILER.DOC" file,  you will have to  modify  the 
  186.  
  187.         batch file for your particular compiler.
  188.          
  189.              The  pass or passes of the compiler will  be  executed, 
  190.  
  191.         followed by the linking process.   The final program will be 
  192.  
  193.         loaded and run, then the files generated by the process will 
  194.  
  195.         be erased to prevent filling the disk up. 
  196.  
  197.  
  198.  
  199.                                  Page 5
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.                         Chapter 1 - Getting Started
  210.  
  211.  
  212.  
  213.              If you have a hard disk available, it will be up to you 
  214.  
  215.         to  modify  the  batch file to perform the  above  described 
  216.  
  217.         operations.
  218.  
  219.              Even though you will have a lot of files to compile and 
  220.  
  221.         run, you will find that a batch file similar to this will do 
  222.  
  223.         most of the work for you and you will proceed very quickly.
  224.  
  225.              In order to do the programming exercises, you will need 
  226.  
  227.         to  go  through the same steps as when running  the  example 
  228.  
  229.         programs.   This  is simple to do by simply typing your  own 
  230.  
  231.         filename   with  the  CCL  program  call.    It  is   highly 
  232.  
  233.         recommended  that you do the programming exercises  to  gain 
  234.  
  235.         the programming experience.
  236.  
  237.                                   LIST.EXE
  238.  
  239.              This  file will list the source files for you with line 
  240.  
  241.         numbers  and  filename.   To  use  it,  simply  type  "LIST" 
  242.  
  243.         followed by the appropriate filename.   Type LIST  FIRSTEX.C 
  244.  
  245.         now  for  an example.   The C source code is given later  in 
  246.  
  247.         Chapter 14 along with a brief description of its operation.
  248.  
  249.                                 PRINTALL.BAT
  250.  
  251.              This is a batch file that will call the above  LIST.EXE 
  252.  
  253.         file  once for each of the example C programs,  printing all 
  254.  
  255.         of  the  files out.   If you want a hardcopy of all  of  the 
  256.  
  257.         files,  enter PRINTALL and watch as your printer fills about 
  258.  
  259.         150 sheets of paper with C programs. 
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.                                  Page 6
  283.  
  284.